package com.ck.autoconfig.tenant.service;

import com.ck.autoconfig.tenant.mapper.TenantMapper;
import com.ck.common.entity.TenantEntity;
import com.ck.common.enums.CommonStatusEnum;
import com.ck.common.exception.BusinessException;
import com.ck.common.utils.date.DateUtils;
import lombok.RequiredArgsConstructor;


/**
 * @author ck
 * @date 2024/4/10 15:10
 */
@RequiredArgsConstructor
public class TenantServiceImpl implements TenantService {
    private final TenantMapper tenantMapper;



    @Override
    public Boolean validTenant(Long id) {
        TenantEntity tenant = tenantMapper.selectById(id);
        if (tenant == null) {
            throw new BusinessException("租户不存在");
        }
        if (tenant.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) {
            throw new BusinessException("该租户已被禁用");
        }
        if (DateUtils.isExpired(tenant.getExpireTime())) {
            throw new BusinessException("该租户已过期");
        }
        return true;
    }

}
